package com.xju.ExampleSystem;

import java.util.ArrayList;
import java.util.List;

public class Example {

	private List<Question> qList;
	private List<String> asksList;
	private int current = 0;
	private boolean hasNext = false;
	private int rightCount = 0;

	public Example() {
		qList = new ArrayList<Question>();
		asksList = new ArrayList<String>();

	}

	public int getCurrent() {
		return current;
	}

	public boolean isHasNext() {
		return hasNext;
	}

	public void Asks(String ask) {
		asksList.add(ask);
		checkhasNext();
		if (hasNext) {
			current++;
		}
	}

	public void setqList(List<Question> qlist) {
		this.qList = qlist;
		checkhasNext();
	}

	private void checkhasNext() {
		if (current < qList.size() - 1)
			hasNext = true;
		else {
			hasNext = false;
		}
	}

	public Question getCurrentQuestion() {
		checkhasNext();
		return qList.get(current);
	}

	public int getQuestionCount() {
		return qList.size();
	}

	public float getScore() {
		float score = 0;
		int rights = 0;
		for (int i = 0; i < asksList.size(); i++) {
			String ra = qList.get(i).getRightAnswer();
			String an = asksList.get(i);
			System.out.println("RightAnswers:" + ra);
			System.out.println("Answers:" + an);
			if (ra.equals(an)) {
				rights++;
			}
		}
		rightCount = rights;
		score = ((float) rights) / ((float) qList.size()) * 100;
		return score;
	}

	public int getRightCount() {
		return rightCount;
	}

	@Override
	public String toString() {
		return "Example [qList=" + qList + ", asksList=" + asksList
				+ ", current=" + current + ", hasNext=" + hasNext + "]";
	}

}